<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Home</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="css/fontastic.css">
    <!-- Google fonts - Roboto -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700">
    <!-- jQuery Circle-->
    <link rel="stylesheet" href="css/grasp_mobile_progress_circle-1.0.0.min.css">
    <!-- Custom Scrollbar-->
    <link rel="stylesheet" href="vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="css/custom.css">
    <!-- Favicon-->
    <link rel="shortcut icon" href="img/favicon.ico">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
  </head>
  <body>
    <!-- Side Navbar -->
    <nav class="side-navbar">
      <div class="side-navbar-wrapper">
        <!-- 头-->
        <div class="sidenav-header d-flex align-items-center justify-content-center">
          <!-- User Info-->
          <div class="sidenav-header-inner text-center"><img src="img/avatar-7.jpg" alt="person" class="img-fluid rounded-circle">
            <h2 class="h5">Welcome</h2><span id="username"></span>
          </div>
          <!-- Small Brand information, appears on minimized sidebar-->
          <div class="sidenav-header-logo"><a href="index.html" class="brand-small text-center"> <strong>B</strong><strong class="text-primary">D</strong></a></div>
        </div>
        <!-- 左侧菜单-->
        <div class="main-menu">
          <h5 class="sidenav-heading">Main</h5>
          <ul id="side-main-menu" class="side-menu list-unstyled">                  
            <li><a href="index.html"> <i class="icon-home"></i>Home                             </a></li>
            <li><a href="forms.html"> <i class="icon-form"></i>商品管理                             </a></li>
            <li><a href="charts.html"> <i class="fa fa-bar-chart"></i>待开发                             </a></li>
            <li id="admin"><a href="tables.html"> <i class="icon-grid"></i>用戶管理                             </a></li>
            <li><a href="#exampledropdownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>Example dropdown </a>
              <ul id="exampledropdownDropdown" class="collapse list-unstyled ">
                <li><a href="#">Page</a></li>
                <li><a href="#">Page</a></li>
                <li><a href="#">Page</a></li>
              </ul>
            </li>
            <li> <a href="#"> <i class="icon-mail"></i>Demo
                <div class="badge badge-warning">6 New</div></a></li>
          </ul>
        </div>
        <div class="admin-menu">
          <h5 class="sidenav-heading">Second menu</h5>
          <ul id="side-admin-menu" class="side-menu list-unstyled"> 
            <li> <a href="#"> <i class="icon-screen"> </i>Demo</a></li>
            <li> <a href="#"> <i class="icon-flask"> </i>Demo
                <div class="badge badge-info">Special</div></a></li>
            <li> <a href=""> <i class="icon-flask"> </i>Demo</a></li>
            <li> <a href=""> <i class="icon-picture"> </i>Demo</a></li>
          </ul>
        </div>
      </div>
    </nav>
    <div class="page">
      <!-- navbar-->
      <header class="header">
        <nav class="navbar">
          <div class="container-fluid">
            <div class="navbar-holder d-flex align-items-center justify-content-between">
              <div class="navbar-header"><a id="toggle-btn" href="#" class="menu-btn"><i class="icon-bars"> </i></a><a href="index.html" class="navbar-brand">
                  <div class="brand-text d-none d-md-inline-block"><span>商品</span><strong class="text-primary">管理系统</strong></div></a></div>
              
                <!-- Log out-->
                <li class="nav-item"><a onclick="logout()" href="#" class="nav-link logout"> <span class="d-none d-sm-inline-block">Logout</span><i class="fa fa-sign-out"></i></a></li>
              </ul>
            </div>
          </div>
        </nav>
      </header>
      <!-- 页脚 -->
      <footer class="main-footer">
        <div class="container-fluid">
          <p style="text-align: center;">页脚</p>
        </div>
      </footer>
    </div>
    <!-- JavaScript files-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/popper.js/umd/popper.min.js"> </script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
    <script src="js/grasp_mobile_progress_circle-1.0.0.min.js"></script>
    <script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
    <script src="vendor/chart.js/Chart.min.js"></script>
    <script src="vendor/jquery-validation/jquery.validate.min.js"></script>
    <script src="vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/charts-home.js"></script>
    <!-- Main File-->
    <script src="js/front.js"></script>
  </body>
  <script type="text/javascript">
	  var name = "";
	  //权限
	  var a = "n";
	  var b = "n";
	  var c = "n";
	  var admin=false;
	  
	  //页面加载时调用
	  $(function() {
	  	islogin();
		QUANXIAN();
	  })
	  
	  //是否登录
	  function islogin() {
	  	$.ajax({
	  		url: "http://localhost:8080/items/show",
	  		data: null,
	  		async: false,
	  		success: function(data) {
	  			console.log(data);
	  			if (data.status == 201) {
	  				alert(data.msg);
	  				window.location = "http://localhost:8080/cadiEditSoftware/login.html"
	  			}
	  			if (data.status == 200) {
	  				alert(data.msg);
	  				// alert(data.data);//用户名
	  				$("#username").text(data.data);
	  				// selectUserAll();
	  				// $("#qdl").hide();
	  				// $("h1").html("<span>欢迎你&nbsp;</span>" + data.data).css('color', 'red');
	  				// document.getElementById("logout").style.display = "block";
	  				//查询所有记录
	  				// selectAll();
	  			}
	  
	  		},
	  		error: function(e) {
	  			alert("出错");
	  			alert(e.responseText);
	  			window.location = "http://localhost:8080/cadiEditSoftware/login.html"
	  		},
	  	})
	  }
	  
	  //权限判断
	  function QUANXIAN() {
	  	$.ajax({
	  		url: "http://localhost:8080/user/session",
	  		data: null,
	  		async: false,
	  		success: function(data) {
	  			console.log(data.data);
	  			//权限
	  			a = data.data.user_edit_top;
	  			b = data.data.user_edit_middle;
	  			c = data.data.user_edit_below;
	  			admin = data.data.user_edit_admin;
	  			name = data.data.user_name;
	  			console.log(a, b, c, name, admin);
				//判断是否为管理员
				if(!admin){
					$("#admin").remove();
				}
	  		},
	  		error: function(e) {
	  			alert("出错");
	  			alert(e.responseText);
	  		},
	  	})
	  }
	  
	  //退出
	  function logout() {
	  	$.ajax({
	  		url: "http://localhost:8080/user/logout",
	  		data: null,
	  		success: function(result) {
	  			alert("退出成功");
	  			location.reload();
	  		},
	  	})
	  }
	  	
  </script>
</html>